//
//  DetailBace.m
//  项目
//
//  Created by 焦钟培 on 15-1-6.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "DetailBace.h"
#import "DetailModel.h"
#import "DB.h"

@implementation DetailBace
+ (NSString *)insertIntoDetailWithDetailModel: (DetailModel *)detailModel
{
    sqlite3 *dbpoint = [DB openDB];
    NSString *str = [NSString stringWithFormat:@"insert into detail(detail_id,detail_tit,detail_http) values(%ld,'%@','%@')",detailModel.detail_id,detailModel.detail_tit,detailModel.detail_http];
    int result = sqlite3_exec(dbpoint, [str UTF8String], nil, nil, nil);
    if (result == SQLITE_OK) {
        return @"成功";
    }else{
        return @"已收藏";
    }
}
+ (void)deleteFromDetailWithDetail_id: (NSInteger)detail_id
{
    sqlite3 *dbpoint = [DB openDB];
    NSString *str = [NSString stringWithFormat:@"delete from detail where detail_id=%ld",detail_id];
    int result = sqlite3_exec(dbpoint, [str UTF8String], nil, nil, nil);
    if (result == SQLITE_OK) {
        
    }else{
        
    }
}
+ (NSArray *)selectAllDetail
{
    sqlite3 *dbpoint = [DB openDB];
    sqlite3_stmt *stmt = nil;
    NSString *selectStr = @"select detail_id,detail_tit,detail_http from detail";
    int result = sqlite3_prepare_v2(dbpoint, [selectStr UTF8String], -1, &stmt, nil);
    NSMutableArray *array = [NSMutableArray array];
    if (result == SQLITE_OK) {
        while (sqlite3_step(stmt) == SQLITE_ROW) {
            int nid = sqlite3_column_int(stmt, 0);
            const unsigned char *tit = sqlite3_column_text(stmt, 1);
            const unsigned char *http = sqlite3_column_text(stmt, 2);
            NSString *detail_tit = [NSString stringWithUTF8String:(const char *)tit];
            NSString *detail_http = [NSString stringWithUTF8String:(const char *)http];
            DetailModel *detailModel = [DetailModel detailModelWithDetail_id:nid detail_tit:detail_tit detail_http:detail_http];
            [array addObject:detailModel];
        }
        
    }
    sqlite3_finalize(stmt);
    return array;
}
@end
